package com.dove.utils.redData;



public class ResultUtil {
    /**
     * 返回成功，传入返回体具体出參
     */
    public static <T> ResultBody<T> success(final T t) {
        final ResultBody<T> result = new ResultBody<T>();
        result.setCode(200);
        result.setInfo("success");
        result.setData(t);
        return result;
    }

    /**
     * 提供给部分不需要出參的接口
     */
    public static <T> ResultBody<T> success() {
        return success(null);
    }

    /**
     * 自定义错误信息
     */
    public static <T> ResultBody<T> error(final Integer code, final String msg) {
        final ResultBody<T> result = new ResultBody<T>();
        result.setCode(code);
        result.setInfo(msg);
        return result;
    }

    /**
     * 请求失败，返回错误码及错误信息
     *
     * @param code 错误码
     * @param msg  错误信息
     * @return
     */
    public static <T> ResultBody<T> error(final Integer code, final String msg, final T data) {
        final ResultBody<T> result = new ResultBody<T>();
        result.setCode(code);
        result.setData(data);
        result.setInfo(msg);
        return result;
    }

    public static <T> ResultBody<T> error(final int code, final String info) {
        final ResultBody<T> result = new ResultBody<T>();
        result.setCode(code);
        result.setInfo(info);
        return result;
    }
}